﻿/*Author：Lary Pan(itolmqj123@gmail.com)
 *Date  ：2016/7/31
 *Tips  ：UI基类 for Tab
 * */
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class UIBase4Tab : UIBase 
{
	private Dictionary<GameObject, Action<GameObject>> dict1 	= new Dictionary<GameObject, Action<GameObject>>();
	private Dictionary<int, Action<int>> dict2 					= new Dictionary<int, Action<int>>();
	
	#region 点击事件监听
	public void SetBtnClick(GameObject btn, Action<GameObject> action)
	{
		base.SetBtnClick(btn, "VPBtnClick");

		if (action == null) return;
		if (dict1.ContainsKey(btn)) dict1.Remove(btn);
		dict1.Add(btn, action);
	}
	
	//列表点击监听
	public void SetItemClick(GameObject item, int index, Action<int> action)
	{
		base.SetItemClick(item, index, "VPItemClick");

		if (dict2.ContainsKey(index)) dict2.Remove(index);
		dict2.Add(index, action);
	}
	#endregion    

	void VPBtnClick(GameObject obj)
	{
		Action<GameObject> action;
		if (dict1.TryGetValue(obj, out action)) action(obj);
	}

	void VPItemClick(int index)
	{
		Action<int> action;
		if (dict2.TryGetValue(index, out action)) action(index % 1000);
	}
}
